/** 构建路由表 */
import React, { lazy } from 'react'
import { Navigate } from 'react-router-dom'
import A from '../view-router/components/A'

/** a children 二级路由 */
const aRoutes = [
  {
    path: '/a',
    component: () => <Navigate to='/a/a1' />,
  },
  {
    name: 'a-a1',
    path: '/a/a1',
    /* 懒加载的时候使用的是 webpack 中的动态导入，将 chunk 名相同的打包到同一个 chunk 中 */
    component: lazy(() => import(/* webpackChunkName: "AChild" */'../view-router/components/A1')),
    meta: {}
  },
  {
    name: 'a-a2',
    path: '/a/a2',
    component: lazy(() => import(/* webpackChunkName: "AChild" */'../view-router/components/A2')),
    meta: {}
  },
  {
    name: 'a-a3',
    path: '/a/a3',
    component: lazy(() => import(/* webpackChunkName: "AChild" */'../view-router/components/A3')),
    meta: {}
  }
]

/** 一级路由 */
const routes = [
  {
    name: 'a',
    path: '/a',
    component: A,
    meta: {},
    children: aRoutes
  },
  {
    name: 'b',
    path: '/b',
    component: lazy(() => import('../view-router/components/B')),
    meta: {}
  },
  {
    name: 'c',
    path: '/c/:id?/:name?',
    component: lazy(() => import('../view-router/components/C')),
    meta: {}
  },
  {
    path: '*',
    component: () => {
      return <Navigate to={{
        pathname: '/a',
        search: '?from=404'
      }} />
    }
  }
]

export default routes